package com.cya.forumproject.controller;

import com.cya.forumproject.common.AppResult;
import com.cya.forumproject.exception.ApplicationException;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

/**
 * @author ：陈奕安（3048279304@qq.com）
 * @date ：Created in 2025/9/18 23:49
 * @description：
 * @modified By：
 * @version:
 */
@Api(tags = "测试类的相关接口")
@RestController//表明返回的是数据,而不是url
@RequestMapping("/test")
public class TestController {

    @ApiOperation("测试接口1，显示你好springboot")
    @GetMapping("/hello")
    public String hello(){
        return "hello,Spring boot";
    }
    @ApiOperation("传入姓名显示信息")
    @PostMapping("/helloByName")
    public AppResult helloByName(@ApiParam("姓名")@RequestParam("name") String name){
        return AppResult.success("name:"+name);
    }
@ApiOperation("显示抛出异常信息")
    @GetMapping("/execption")
    public AppResult testException() throws Exception {
    throw new Exception("这是一个异常信息");
    }

    @ApiOperation("显示自定义异常信息")
    @GetMapping("appException")
    public AppResult testApplicationException(){
        throw new ApplicationException("这是一个ApplicationException异常");
    }
}